# _*_ coding: utf-8 _*_
from odoo import models, api, fields, _
from odoo.exceptions import Warning


class OLStockStrap(models.Model):
    _inherit = ["stock.scrap", "stock.view.quant.mixin"]
    _name = "stock.scrap"

    state = fields.Selection([
        ('draft', 'Draft'),
        ('submit', 'Submitted'),
        ('approve', 'Approved'),
        ('done', 'Done')], string='Status', default="draft")
    product_uom_id_readonly = fields.Many2one(
        'product.uom', string='Unit of Measure',
        related='product_uom_id', store=True, readonly=True)

    @api.multi
    def action_submit(self):
        return self.write({'state': 'submit'})

    @api.multi
    def action_approve(self):
        return self.write({'state': 'approve'})

    @api.multi
    def action_do_scrap(self):
        return self.do_scrap()

    @api.multi
    def do_scrap(self):
        for scrap in self:
            if scrap.state == 'approve':
                super(OLStockStrap, self).do_scrap()
        return True

    @api.multi
    def action_view_quants(self):
        self.ensure_one()
        return self.action_view_quant_by_product_ids([self.product_id.id])